package RMI_Server;

import java.rmi.NoSuchObjectException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import Data.CourseData;
import Data.Statistic;
import Data.TeachingPlan;
import Data.TimeLimitForm;
import Data.UserData;
import Data.WholeFrameData;
import Interface_Data.CourseDataI;
import Interface_Data.StatisticI;
import Interface_Data.TeachingPlanI;
import Interface_Data.TimeLimitI;
import Interface_Data.UserDataI;
import Interface_Data.WholeFrameDataI;

public class Entry {
	Registry registry;
	public void startServer() throws Exception {
		UserData userData = new UserData();
		UserDataI userDataI = (UserDataI) UnicastRemoteObject.exportObject(
				userData, 0);
		CourseData courseData = new CourseData();
		CourseDataI courseDataI = (CourseDataI) UnicastRemoteObject
				.exportObject(courseData, 0);
		WholeFrameData wholeFrameData = new WholeFrameData();
		WholeFrameDataI wholeFrameDataI = (WholeFrameDataI) UnicastRemoteObject
				.exportObject(wholeFrameData, 0);
		TimeLimitForm timeLimitForm = new TimeLimitForm();
		TimeLimitI timeLimitI = (TimeLimitI) UnicastRemoteObject.exportObject(
				timeLimitForm, 0);
		Statistic statistic = new Statistic();
		StatisticI statisticI = (StatisticI) UnicastRemoteObject.exportObject(
				statistic, 0);
		TeachingPlan teachingplan = new TeachingPlan();
		TeachingPlanI teachingplanI = (TeachingPlanI) UnicastRemoteObject
				.exportObject(teachingplan, 0);
		// Bind the remote object's stub in the registry
		registry = LocateRegistry.createRegistry(2001);
		registry.rebind("userData", userDataI);
		registry.rebind("courseData", courseDataI);
		registry.rebind("wholeFrameData", wholeFrameDataI);
		registry.rebind("timeLimitForm", timeLimitI);
		registry.rebind("statistic", statisticI);
		registry.rebind("teachingplan", teachingplanI);
	}
     
	public void endServer(){
		try {
			java.rmi.server.UnicastRemoteObject.unexportObject(registry, true);
		} catch (NoSuchObjectException ex1) {
			ex1.printStackTrace();
		}
	}
	
}
